package Ep06_BinaryTree.BFS._0100;

import Ep06_BinaryTree.TreeNode;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/4/25 11:53
 * 说明：100
 * 严格意义上来说也是后序遍历。因为先判断 resLeft，再判断 resRight，最后将结果返回给 root
 */

public class Mine {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        return Compare(p,q);
    }

    public boolean Compare(TreeNode left, TreeNode right){
        if (left == null && right == null) return true;
        else if (left != null && right == null) return false;
        else if (right != null && left == null) return false;
        else if (right.val != left.val) return false;
        else {
            boolean resLeft = Compare(left.left, right.left);
            boolean resRight = Compare(left.right, right.right);
            boolean result = resLeft && resRight;
            return result;
        }
    }
}

